package com.s666.demo.exception;

import com.s666.demo.common.response.Result;
import com.s666.demo.common.response.ResultVO;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author lijin
 */
@Component
public class MessageRender {
    /**
     * 返回视图结果
     * @param ce
     * @return
     */
    public ModelAndView html(CommonException ce) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("error/404.html");
        modelAndView.addObject("rsp_code", ce.getCode());
        modelAndView.addObject("rsp_msg", ce.getMessage());
        return modelAndView;
    }

    /**
     * 返回json结果
     * @param ce
     * @return
     */
    public ResultVO json(CommonException ce) {
        ResultVO resultVO = Result.fail(ce.getCode(), ce.getMessage());
        return resultVO;
    }
}

